package gamesys.games.particlesystem.effects
{
	import gamesys.games.particlesystem.core.ParticleData;
	import gamesys.games.particlesystem.utils.Range;

	/**
	 * @author robertthurston
	 */
	public class SpringEffect implements IEffect
	{
		private var _distanceX:Range;
		private var _distanceY:Range;
		private var _speedX:Range;
		private var _speedY:Range;

		public function SpringEffect(distanceX:Range, distanceY:Range, speedX:Range, speedY:Range)
		{
			_distanceX = distanceX;
			_distanceY = distanceY;
			_speedX = speedX;
			_speedY = speedY;
		}

		public function reset(particleData:ParticleData):void
		{
			particleData.springDistanceX = _distanceX.range;
			particleData.springDistanceY = _distanceY.range;
			particleData.springSpeedX = _speedX.range;
			particleData.springSpeedY = _speedY.range;
			particleData.springRotationX = 0;
			particleData.springRotationY = 0;
		}

		public function update(particleData:ParticleData):void
		{
			particleData.springRotationX += particleData.springSpeedX;
			particleData.springRotationY += particleData.springSpeedY;
			
			particleData.x += Math.sin(particleData.springRotationX) * particleData.springDistanceX;
			particleData.y += Math.cos(particleData.springRotationY) * particleData.springDistanceY;
		}
	}
}
